package edu.hhu.config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;

import edu.hhu.controller.AdminController;
import edu.hhu.controller.AnalyseController;
import edu.hhu.controller.BaController;
import edu.hhu.controller.BasicController;
import edu.hhu.controller.ChartController;
import edu.hhu.controller.LoginController;
import edu.hhu.controller.PaiCaiController;
import edu.hhu.controller.PoiController;
import edu.hhu.controller.SummeryController;
import edu.hhu.controller.TableController;
import edu.hhu.controller.TreeController;
import edu.hhu.model.Cjscjt;
import edu.hhu.model.User;

public class MyAppConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		// TODO Auto-generated method stub
		me.setDevMode(true);
		me.setEncoding("utf-8");
		me.setViewType(ViewType.JSP);

	}

	@Override
	public void configRoute(Routes me) {
		// TODO Auto-generated method stub
		me.add("/", LoginController.class);
		me.add("/basic", BasicController.class);
		me.add("/basic1", BaController.class);
		me.add("/home",SummeryController.class);
		me.add("/dynamic/tree", TreeController.class);
		me.add("/dynamic/chart", ChartController.class);
		me.add("/dynamic/table", TableController.class);
		me.add("/dynamic/excel", PoiController.class);
		me.add("/home/chart", ChartController.class);
		me.add("/paicai", PaiCaiController.class);
		me.add("/admin", AdminController.class);
		me.add("/analyse", AnalyseController.class);
	}

	@Override
	public void configPlugin(Plugins me) {
		// TODO Auto-generated method stub
		Prop prop = PropKit.use("database.properties");
		String string = prop.get("MySQL_url");
		C3p0Plugin cp = new C3p0Plugin(prop.get("MySQL_url"),
				prop.get("MySQL_user"), prop.get("MySQL_password"));
		me.add(cp);
		/*ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
		me.add(arp);*/
		ActiveRecordPlugin arp = new ActiveRecordPlugin("mysql", cp);
		me.add(arp);
		arp.addMapping("user", User.class);
		//arp.addMapping("cjscjt", Cjscjt.class);
		//arp.addMapping("cjkj", )
		//arp.addMapping("article", "article_id", Article.class);
	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub

	}

	@Override
	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub
		me.add(new ContextPathHandler("basePath"));

	}

}
